<template>
  <div class="content-article">
    <div class="content-article-title">文章管理</div>
    <div class="scecher">
      <div class="input-seacher">
        <el-input placeholder="请输入内容" v-model="seacherArticle" clearable>
        </el-input>
      </div>
      <div class="clickAnniu">
        <el-button type="primary" icon="el-icon-search">搜索</el-button>
      </div>
    </div>
    <div>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="博文类型">
                <span
                  class="spanarticle"
                  v-for="(item, index) in scope.row.classifications"
                  >{{ item.classiName }}</span
                >
              </el-form-item>
              <el-form-item label="博文标签">
                <span
                  class="spanarticle1"
                  v-for="(item, index) in scope.row.documentTypes"
                  >{{ item.docName }}</span
                >
              </el-form-item>
              <el-form-item label="修改时间">
                <i class="el-icon-time"></i>
                <span style="margin-left: 6px">{{
                  scope.row.artUpdateTime
                }}</span>
              </el-form-item>
              <el-form-item label="博文标题">
                <span class="titleSpan" style="margin-left: 6px">{{
                  scope.row.artTitle
                }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="id" width="80">
          <template slot-scope="scope">
            <i class="el-icon-price-tag"></i>
            <span style="margin-left: 10px">{{ scope.row.artId }}</span>
          </template>
        </el-table-column>

        <el-table-column label="浏览数量" width="80">
          <template slot-scope="scope">
            <i class="el-icon-view"></i>
            <span style="margin-left: 10px">{{ scope.row.artBrowseSize }}</span>
          </template>
        </el-table-column>

        <el-table-column label="评论数量" width="80">
          <template slot-scope="scope">
            <i class="el-icon-chat-line-round"></i>
            <span style="margin-left: 10px">{{
              scope.row.artCommentsSize
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="点赞数量" width="80">
          <template slot-scope="scope">
            <i class="el-icon-thumb"></i>
            <span style="margin-left: 10px">{{ scope.row.artThumbsSize }}</span>
          </template>
        </el-table-column>

        <el-table-column label="用户" width="180">
          <template slot-scope="scope">
            <span>
              <img class="imagesss" :src="scope.row.user.userImg" alt="" />
            </span>
            <span
              style="
                margin-left: 10px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
              "
              >{{ scope.row.user.userName }}</span
            >
          </template>
        </el-table-column>

        <el-table-column label="标题" width="280">
          <template slot-scope="scope">
            <el-popover trigger="hover" placement="top">
              <p>
                <img
                  style="width: 200px; height: 150px"
                  :src="scope.row.aetImg"
                  alt=""
                />
              </p>
              <p>描述: {{ scope.row.artDescribe }}</p>
              <div slot="reference" class="name-wrapper">
                <el-tag size="medium">{{ scope.row.artTitle }}</el-tag>
              </div>
            </el-popover>
          </template>
        </el-table-column>

        <el-table-column label="日期" width="150">
          <template slot-scope="scope">
            <i class="el-icon-time"></i>
            <span style="margin-left: 10px">{{ scope.row.artUpdateTime }}</span>
          </template>
        </el-table-column>

        <el-table-column label="私密/公开" width="140">
          <template slot-scope="scope">
            <el-tooltip
              :content="'当前状态: ' + scope.row.artStatus"
              placement="top"
            >
              <el-switch
                v-model="scope.row.artStatus"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="1"
                :inactive-value="0"
                active-text="公开"
                inactive-text="私密"
              >
              </el-switch>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column label="审核状态" width="160">
          <template slot-scope="scope">
            <el-tooltip
              :content="'当前状态: ' + scope.row.artAuditStatus"
              placement="top"
            >
              <el-switch
                v-model="scope.row.artAuditStatus"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="1"
                :inactive-value="0"
                active-text="通过"
                inactive-text="待审核"
                @click.native="
                  updateartAuditStatus($event, scope.row.artAuditStatus)
                "
              >
              </el-switch>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column label="是否删除" width="160">
          <template slot-scope="scope">
            <el-tooltip
              :content="'当前状态: ' + scope.row.artIsdelete"
              placement="top"
            >
              <el-switch
                v-model="scope.row.artIsdelete"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="0"
                :inactive-value="1"
                active-text="显示"
                inactive-text="删除"
              >
              </el-switch>
            </el-tooltip>
          </template>
        </el-table-column>

        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <div class="limitpage" style="margin-left: 30%; margin-top: 30px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :pager-count="5"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "ArticleAdministration",
  data() {
    return {
      tableData: [],
      seacherArticle: "", //搜索

      currentPage: 1, //当前默认显示第几页

      start: 0, //当前页面从第几条数据开始展示

      pageSize: 10, // 每页显示多少条数据，记住这里一定要是10的倍数，不然无效

      total: 0, //数据总条数
    };
  },
  mounted() {
    //查询所有博文信息
    this.getArticleInfo(this.currentPage, this.pageSize);
  },
  methods: {
    //获取文章所有数据
    getArticleInfo(pageNum, pageSize) {
      const that = this;
      axios
        .post(
          "/aabbcc/adminArticle/selectAllArticle/" + pageNum + "/" + pageSize
        )
        .then(function (res) {
          if (res.data.code == 200) {
            that.tableData = res.data.obj.comData;
            that.total = res.data.obj.total;
            that.open2("查询成功");
          } else {
            that.open4("查询失败");
          }
        });
    },
    updateartAuditStatus(e, status) {
      console.log("e:", e);
      alert(status);
    },
    handleEdit(index, row) {
      console.log(index, row);
    },

    //分页  size-change  pageSize 改变时会触发 每页条数

    handleSizeChange(val) {
      this.pageSize = val;
      // this.getA(); //引入你要加载的数据函数
      const loading = this.$loading({
        lock: true,

        text: "加载中",

        spinner: "el-icon-loading",

        background: "rgba(0, 0, 0, 0.7)",
      });
      this.getArticleInfo(this.currentPage, val);
      loading.close();
    },

    //current-change  currentPage 改变时会触发  当前页

    async handleCurrentChange(val) {
      //数据较多，加载较慢时可以加一个elementUI的加载框，起到缓冲且项目优化美观作用

      const loading = this.$loading({
        lock: true,

        text: "加载中",

        spinner: "el-icon-loading",

        background: "rgba(0, 0, 0, 0.7)",
      });
      this.getArticleInfo(val, this.pageSize);
      loading.close();
    },

    //弹框是否确认
    open() {
      this.$confirm("是否执行操作", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },
    open4(message) {
      //错误提示框
      this.$message({
        showClose: true,
        message: message,
        type: "error",
      });
    },
    open2(message) {
      //成功提示框
      this.$message({
        showClose: true,
        message: message,
        type: "success",
      });
    },
  },
};
</script>

<style scoped>
.scecher {
  width: 100%;
  height: 40px;
  margin-top: 20px;
  margin-bottom: 20px;
  display: flex;
}
.input-seacher {
  width: 200px;
}
.imagesss {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #ccc;
  position: relative;
  top: 5px;
}

.spanarticle {
  padding: 4px 8px;
  border: 1px solid #eff8ea;
  background: #f0f9eb;
  color: #67c23a;
  font-size: 12px;
  border-radius: 3px;
  margin-right: 15px;
}

.spanarticle1 {
  padding: 4px 8px;
  border: 1px solid #fdf6ec;
  background: #fdf6ec;
  color: #f3c16f;
  font-size: 12px;
  border-radius: 3px;
  margin-right: 15px;
}
.titleSpan {
  background-color: #ecf5ff;
  border-color: #d9ecff;
  height: 32px;
  padding: 5px 10px;
  line-height: 30px;
  font-size: 12px;
  border-width: 1px;
  border-style: solid;
  border-radius: 4px;
  box-sizing: border-box;
  white-space: nowrap;
  color: #409eff;
}
.content-article {
  width: 100%;
  height: 100%;
}
.content-article-title {
  height: 30px;
  font-size: 18px;
  padding-bottom: 5px;
  border-bottom: 2px solid #ccc;
}

.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  /* margin-right: 0; */
  margin-bottom: 0;
  width: 50%;
}
</style>